package com.javafx06.util;

import com.javafx06.entity.Staff;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class DBUtil {

    // String name, String idcard, String gender, String age, String zhiwei, String birthday, String depart, String enterDate)

    public static void add(Staff staff){
        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

        try (Connection connection = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/demo111", "root", "root");){
            PreparedStatement statement = connection.prepareStatement("insert into staffs values(?,?,?,?,?,?,?,?) ");
            statement.setString(1, staff.getName());
            statement.setString(2, staff.getIdcard());
            statement.setString(3, staff.getGender());
            statement.setString(4, staff.getAge());
            statement.setString(5, staff.getZhiwei());
            statement.setString(6, staff.getBirthday());
            statement.setString(7, staff.getDepart());
            statement.setString(8, staff.getEnterDate());
            statement.execute();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
